<?php
class Pageley_Query_Condition_AggregateTests extends Pageley_Test_Case {
	private $entity;
	
	public function setUp() {
		$string = new Pageley_Domain_Attribute_Basic("string");
		$number = new Pageley_Domain_Attribute_Basic("number");
		$type = new Pageley_Domain_BasicType(
			"Pageley_Commerce",
			"Article",
			new Pageley_Util_ArrayMap(array(
				"name" => $string,
				"price" => $number
			))
		);
		$this->entity = $type->newInstance();
	}
	
	public function testAnd() {
		$condition = new Pageley_Query_Condition_AndGroup(
			new Pageley_Util_ArrayMap(array(
				new Pageley_Query_Condition_Equals("name", "foo"),
				new Pageley_Query_Condition_GreaterThan("price", 5.0),
				new Pageley_Query_Condition_LessThan("price", 10.0)
		)));
		$this->entity->set("name", "foo");
		$this->entity->set("price", 5.1);
		$this->assertTrue($condition->matches($this->entity));
		$this->entity->set("price", 10.1);
		$this->assertFalse($condition->matches($this->entity));
	}
	
	public function testOr() {
		$condition = new Pageley_Query_Condition_OrGroup(
			new Pageley_Util_ArrayMap(array(
				new Pageley_Query_Condition_Equals("price", 5.0),
				new Pageley_Query_Condition_GreaterThan("price", 7.5)
		)));
		$this->entity->set("price", 5.0);
		$this->assertTrue($condition->matches($this->entity));
		$this->entity->set("price", 7.4);
		$this->assertFalse($condition->matches($this->entity));
	}
}